#ifndef _ARP_H_
#define _ARP_H_

#include "types.h"
#include "semaphores.h"
#include "user_timers.h"

#define ARP_TABLE_MEM  ((uint8_t *)"arp_table")
#define MAX_ARP_ENTRIES 32

typedef struct {
    uint8_t   dst_mac[6];
    uint8_t   src_mac[6];
    uint16_t  eth_proto;
    uint16_t  hw_type;
    uint16_t  proto_type;
    uint8_t   hw_size;
    uint8_t   proto_size;
    uint16_t  opcode;
    uint8_t   sender_mac[6];
    uint32_t  sender_ip;
    uint8_t   target_mac[6];
    uint32_t  target_ip;
    uint8_t   pad[22];    // min eth-frame length = 64 bytes
}__attribute__((__packed__)) arp_pkt_t;

typedef struct {
    // Exclusion is required b/w
    // emac-rx updating the mac-addr
    // in mac table and tx-task arp-timer
    // wiping out the arp entry
    sem_t     entry_sem;

    uint32_t  ip_address;

    uint8_t   mac_addr[6];
    bool      mac_addr_present;  // Address Present/awaited
    bool      entry_recently_updated;

    gather_list_t  *gather_list; // List of pending messages for this ip_address
    
    user_timer_data_t  *arp_timer;  // timer for this arp request
    uint8_t      arp_count;
}arp_entry_t;


typedef struct
{
    arp_entry_t  entries[MAX_ARP_ENTRIES];
}arp_table_t;


#endif
